﻿using ConsoleApp2.Impl;
using ConsoleApp2.Models;
using ConsoleApp2.Service;
using ConsoleApp2.Utils;

namespace ConsoleApp2.Models;

public class LocalUser
{
    private static List<ConsoleApp2.Models.User> _users = new List<ConsoleApp2.Models.User>();
    public List<ConsoleApp2.Models.User> Users { get; set; } = _users;

    public LocalUser()
    {
        if (_users.Count == 0)
        {
            LoadUsers();
        }
    }

    private void LoadUsers()
    {
        RoleService roleService = new RoleServiceImpl();
        List<Role> roles = roleService.GetAllRoles();
        ConsoleApp2.Models.User user1 = new ConsoleApp2.Models.User()
        {
            UserName = "admin",
            Password = Encory.EncryPwd("aqz1234567890"),
            Phone = "12345678901",
            Email = "1234567890@qq.com",
            NickName = "管理员",
            Roles = new List<ConsoleApp2.Models.Role>() { roles[0] }
        };
        Users.Add(user1); 
    }

    public void AddUser(ConsoleApp2.Models.User user)
    {
        Users.Add(user);
    }
}